﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsAppTest.Dao;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
using WinFormsAppTest.Service;

namespace WinFormsAppTest
{
    public partial class ExamUpdateForm : Form
    {
        public int examid;
        public string state;
        public string measure;
        public string goal;
        public int userid;
        public string adminname;
        public int adminid;

        public ExamUpdateForm()
        {
            InitializeComponent();
        }

        public ExamUpdateForm(int examid, string state, string measure, 
                              string goal, int userid, string adminname,
                              int adminid)
        {
            this.examid = examid;
            this.state = state;
            this.measure = measure;
            this.goal = goal;
            this.userid = userid;
            this.adminname = adminname;
            this.adminid = adminid;
            InitializeComponent();
        }



        //public ExamUpdateForm(int uid, string uname, string upassword, string aname, int aid)
        //{
        //    username = uname;
        //    password = upassword;
        //    adminname = aname;
        //    adminid = aid;
        //    userid = uid;
        //    InitializeComponent();
        //}



        private void ExamUpdate_Closing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                // 关闭进程
                Process.GetCurrentProcess().Kill();
            }
        }

        private void ExamUpdate_Load(object sender, EventArgs e)
        {
            AdminService adminService = new AdminService();

            StatetextBox.Text = state;
            MeasuretextBox.Text = measure;
            GoaltextBox.Text = goal;
            Idlabel.Text = userid.ToString();
            Namelabel.Text = adminService.GetUserById(userid)[0].Name;
        }

        private void Exitbutton_Click(object sender, EventArgs e)
        {
            this.Hide();
            ExamForm f = new ExamForm(adminname, adminid);
            f.ShowDialog();
            this.Dispose();
        }

        //private void OKbutton_Click(object sender, EventArgs e)
        //{
        //    if (string.IsNullOrWhiteSpace(StatetextBox.Text))
        //    {
        //        MessageBox.Show("添加员工基本信息不能为空！");
        //    }
        //    else if (string.IsNullOrWhiteSpace(MeasuretextBox.Text))
        //    {
        //        MessageBox.Show("添加户口情况不能为空！");
        //    }
        //    else if (string.IsNullOrWhiteSpace(GoaltextBox.Text))
        //    {
        //        MessageBox.Show("添加合同管理不能为空！");
        //    }
        //    else if (string.IsNullOrWhiteSpace(InsuretextBox.Text))
        //    {
        //        MessageBox.Show("添加投保情况不能为空！");
        //    }
        //    else
        //    {
        //        //直接调用dao层进行添加
        //        ExamDao Examdao = new ExamDao();
        //        Examdao.UpdateExamById(fileid, StatetextBox.Text, MeasuretextBox.Text,
        //                                 GoaltextBox.Text, InsuretextBox.Text);
        //        MessageBox.Show("更新成功！");
        //        ExamForm f2 = new ExamForm(adminname, adminid);
        //        this.Hide();
        //        f2.ShowDialog();
        //        this.Dispose();

        //    }
        //}

        private void Okbutton_Click(object sender, EventArgs e)
        {

            if (string.IsNullOrWhiteSpace(StatetextBox.Text))
            {
                MessageBox.Show("添加员工基本信息不能为空！");
            }
            else if (string.IsNullOrWhiteSpace(MeasuretextBox.Text))
            {
                MessageBox.Show("添加户口情况不能为空！");
            }
            else if (string.IsNullOrWhiteSpace(GoaltextBox.Text))
            {
                MessageBox.Show("添加合同管理不能为空！");
            }
            else
            {
                //直接调用dao层进行添加
                ExamDao Examdao = new ExamDao();
                Examdao.UpdateExamById(examid, StatetextBox.Text, MeasuretextBox.Text,
                                         GoaltextBox.Text);
                //MessageBox.Show("更新成功！" +fileid+ "  "+ MsgtextBox.Text +"  "+ HousetextBox.Text
                //                            +"  "+ ContracttextBox.Text+"  "+ InsuretextBox.Text);
                MessageBox.Show("更新成功！");
                ExamForm f2 = new ExamForm(adminname, adminid);
                this.Hide();
                f2.ShowDialog();
                this.Dispose();

            }
        }
    }
}
